﻿@{
   
    Layout = "~/Shared/Layouts/_Layout.cshtml";
    Page.Title = "Пребарување на каталог";
    
    var db = Database.Open("VirtualeShop");

    var searchWords = Request["searchTerm"].Split(' ');
    IEnumerable<dynamic> result = Enumerable.Empty<string>();
    
    var sqlSelect = "SELECT productID, title FROM Products WHERE " + 
                    "title LIKE @0 OR description LIKE @0 OR keywords LIKE @0";
    
    foreach(var word in searchWords)
    {
        result = result.Concat(db.Query(sqlSelect, "%" + word + "%").ToList());
    }
    
}

<h1>Резултати од пребарување:</h1>

<p>@result.Count() products found matching: <em>@Request["searchTerm"]</em></p>

<ul id="searchResult">
    @foreach (var item in result)
    {
        <li>
            <a href="/ProductDetails/@item.productID">@item.title</a>
        </li>    
    }
</ul>